//headers 
#include<algorithm>
#include<cassert>
#include<cstdio>
#include<deque>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<deque>
#include<set>
#include<string>
#include<sstream>
#include<stack>
#include<streambuf>
#include<vector>
using namespace std;

//macros
#define LET(x,a) typeof(a) x(a)
#define FOR(i,a,n) for(LET(i,a);i!=n;i++)
#define REP(i,n) FOR(i,0,n)
#define sz size()
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define dbge(x) cout<<#x<<"->"<<x<<endl;
#define PRINT(x) REP(_,x.sz) cout<<x[_]<<" "; cout<<endl;
#define OUT(x) x<<" "
const int INF = (int) 1e8;
#define VI vector<int>
#define VS vector<string>
#define VVI vector< vector<int> >
#define LL long long

//code of suren

VS grid;

bool possible(int x, int y,string test){
  bool ret = false;
  string hor,ver,dia; hor=ver=dia="";
  REP(i,test.sz) {
    if(x+i<grid.sz) hor+=grid[x+i][y];
    if(y+i<grid.sz) ver+=grid[x][y+i];
    if(x+i<grid.sz && y+i<grid.sz) dia+=grid[x+i][y+i];
  }
  if(test==hor || test==ver || test==dia) ret=true;
  return ret;
}

int main(){
  int t;
  while(t--){
    int n,len,query; cin>>n>>len;
    grid.clear(); grid.resize(n);
    REP(i,n) cin>>grid[i];
    PRINT(grid);
    cin>>query; 
    REP(i,query) { 
      string temp; cin>>temp; bool found=false;
      REP(j,n) {
        if(found) break;
        REP(k,len) if( grid[j][k]==temp[0] && possible(j,k,temp)) { cout<<j<<" "<<k<<endl; found=true; break; } 
      }
    }
  }
  return 0;
}
